package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Stock extends BaseObject {
	private Long id;

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Stock))
			return false;
		Stock castOther = (Stock) other;
		return new EqualsBuilder().append(id, castOther.id)
				.append(sdate, castOther.sdate)
				.append(quantity, castOther.quantity)
				.append(product, castOther.product)
				.append(warehouse, castOther.warehouse).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).append(sdate).append(quantity)
				.append(product).append(warehouse).toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("sdate", sdate).append("quantity", quantity)
				.append("product", product)
				.append("warehouse", warehouse).toString();
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })  
	@JoinColumn(name = "warehouseId")
	public Warehouse getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getSdate() {
		return sdate;
	}

	public void setSdate(String sdate) {
		this.sdate = sdate;
	}

	public float getQuantity() {
		return quantity;
	}

	public void setQuantity(float quantity) {
		this.quantity = quantity;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })  
	@JoinColumn(name = "productId")
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}


	private String sdate;
	private float quantity;
	private Product product;
	private Warehouse warehouse;

}
